import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter, FormatStrFormatter

root = ET.parse("D:\\StarCraft\\bwapi-data\\logs\\g.xml").getroot()
generations = root.findall("generation")

win_rate = []

for gen in generations:
	win_rate.append(0)
	numGen = 0
	for g in gen.findall("genome"):
		i = 0
		for o in g.findall("objective"):
			if i == 1:
				if float(o.get("fitness")) > 0:
					win_rate[len(win_rate)-1] += 1
			i += 1
		numGen += 1
	win_rate[len(win_rate)-1] = win_rate[len(win_rate)-1]/numGen

plt.xlabel("generations")
plt.ylabel("fitness")
plt.subplot(111).xaxis.set_major_formatter(FormatStrFormatter('%0.0f'))
plt.title("avarage fitness")
plt.plot(win_rate)
plt.show()